package com.hxzy.servlet.message;

import com.hxzy.service.MessageService;
import com.hxzy.service.impl.MessageServiceImpl;
import com.hxzy.vo.MessageVo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author nick
 */
@WebServlet("/detail")
public class DetailServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");

        //从request请求中获取messageId
        String messageId_str = req.getParameter("messageId");

        //类型转换
        int messageId = Integer.parseInt(messageId_str);

        MessageService service = new MessageServiceImpl();
        MessageVo vo = service.findMessageById(messageId);

        req.setAttribute("vo", vo);
        req.getRequestDispatcher("/details.jsp").forward(req,resp);
    }
}
